package com.chengdu.third.interceptor;

import org.springframework.web.servlet.handler.HandlerInterceptorAdapter;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
/*



登录了后台将会往session放入登录数据，这里判断是否有登录成功返回的数据



*/

/**
 * @author jingbo
 * @create 2021--07--23  20:56
 */
//拦截判断是否存在session，但不知道拦截哪些请求
public class LoginInterceptor extends HandlerInterceptorAdapter {

    @Override
    public boolean preHandle(HttpServletRequest request,
                             HttpServletResponse response,
                             Object handler) throws Exception {
        if (request.getSession().getAttribute("user") == null) {
            response.sendRedirect("/admin");
            return false;
        }
        return true;
    }
}